<template>
  <div class="NoticeList">
    <!-- 顶部页面标题栏 -->
    <!-- <div class="header">
        <div class="backIcon" @click="back">
          <img slot="icon" src="../../assets/transfer/backIcon.png" class="iconImage" />
        </div>
        <div class="theme">通知公告</div>
      </div>-->
    <!-- 页面主体信息区域 -->
    <div class="outermostMargin">
      <van-tabs v-model="activeTab" @change="tabchange">
        <van-tab title="街坊大喇叭" name="街坊大喇叭">
          <!-- 懒加载 列表形式， item内复杂元素布局 -->
          <div class="listBox">
            <!-- <van-list v-model="loading" :finished="finished1" finished-text="没有公告了" @load="onLoad"> -->
              <div v-for="(item, index) in list1" :key="index" style="min-height: 100px;padding: 0 5vw">
                <div class="msgBox" @click="toDet(item)">
                  <div class="textBox">
                    <div class="titles">
                      <span class="mainTitle">{{ item.title }}</span>
                      <p>
                        <span class="time">{{ item.createTime }}</span>
                        <span class="nlfb">{{item.regionName}}</span>
                      </p>
                      
                    </div>
                    <!-- <div class="summary">
                        <span>{{ item.description }}</span>
                      </div>-->
                  </div>
                  <div class="imgBox">
                    <img v-if="item.url" :src="picUrl(item.url)" />
                    <img v-else src="@/assets/aaa/xiaolaba.png" />
                  </div>
                </div>
                <van-divider />
              </div>
            <!-- </van-list> -->
          </div>
        </van-tab>
        <van-tab title="街坊小贴示" name="街坊小贴示">
          <!-- 懒加载 列表形式， item内复杂元素布局 -->
          <div class="listBox">
            <!-- <van-list v-model="loading" :finished="finished2" finished-text="没有内容了" @load="onLoad"> -->
              <div v-for="(item, index) in list2" :key="index" style="min-height: 100px;padding: 30px">
                <div class="msgBox" @click="toDet(item)">
                  <div class="textBox">
                    <div class="titles">
                      <span class="mainTitle">{{ item.title }}</span>
                      <p>
                        <span class="time">{{ item.createTime }}</span>
                        <span class="nlfb">{{item.regionName}}</span>
                      </p>
                    </div>
                    <!-- <div class="summary">
                        <span>{{ item.description }}</span>
                      </div>-->
                  </div>
                  <div class="imgBox">
                    <img :src="item.url? picUrl(item.url): 'https://img.yzcdn.cn/vant/apple-1.jpg'" />
                  </div>
                </div>
                <van-divider />
              </div>
            <!-- </van-list> -->
          </div>
        </van-tab>
        <van-tab title="街坊召集令" name="街坊召集令">
          <!-- 懒加载 列表形式， item内复杂元素布局 -->
          <div class="listBox">
            <!-- <van-list v-model="loading" :finished="finished3" finished-text="没有内容了" @load="onLoad"> -->
              <div v-for="(item, index) in list3" :key="index" style="min-height: 100px;padding: 30px">
                <div class="msgBox" @click="toDet(item)">
                  <div class="textBox">
                    <div class="titles">
                      <span class="mainTitle">{{ item.title }}</span>
                      <p>
                        <span class="time">{{ item.createTime }}</span>
                        <span class="nlfb">{{item.regionName}}</span>
                      </p>
                    </div>
                    <!-- <div class="summary">
                        <span v-html="item.description"></span>
                      </div>-->
                  </div>
                  <div class="imgBox">
                    <img :src="item.url? picUrl(item.url): 'https://img.yzcdn.cn/vant/apple-1.jpg'" />
                  </div>
                </div>
                <van-divider />
              </div>
            <!-- </van-list> -->
          </div>
        </van-tab>
      </van-tabs>
    </div>
     <van-pagination class="pages" v-model="currentPage" :page-count="allcount" force-ellipses @change="onLoad" />
  </div>
</template>
<script>
  export default {
    name: "NoticeList",
    data() {
      return {
        activeTab: "街坊大喇叭",
        list1: [],
        list2: [],
        list3: [],
        finished1: false,
        finished2: false,
        finished3: false,
        loading: false,
        pageSize: 10,
        pageIndex1: 1,
        pageIndex2: 1,
        pageIndex3: 1,
        totalCount1: 0,
        totalCount2: 0,
        totalCount3: 0,
        currentPage: 1,
        allcount: 1,
      };
    },
    created(){
      this.onLoad();
    },
    methods: {
      back() {
        this.$router.isBack = true; // 将返回状态置为触发态，以边路由监听触发返回动画
        this.$router.back(); // 路由向后退一步
      },
      toDet(item) {
        this.$router.push({
          path: "/noticeDet",
          query: {
            detData: item
          }
        });
      },
      tabchange() {
        // this.pageIndex1 = 1;
        // this.pageIndex2 = 1;
        // this.pageIndex3 = 1;
        this.currentPage = 1;
        this.list1 = [];
        this.list2 = [];
        this.list3 = [];
        this.onLoad();
        // this.requestPostNotice1();
        // this.requestPostNotice2();
        // this.requestPostNotice3();
      },
      onLoad() {
        // 异步更新数据
        // setTimeout(() => {
          // 向平安看点list push数据
          // this.loading = true;
          // this.requestPostNotice1();
          switch (this.activeTab) {
            case "街坊大喇叭":
              this.requestPostNotice1();
              break;
            case "街坊小贴示":
              this.requestPostNotice2();
              break;
            case "街坊召集令":
              this.requestPostNotice3();
              break;
            default:
              break;
          }
          // 加载状态结束
          // this.loading = false;
          // 数据全部加载完成
          // if (this.list1.length >= this.totalCount1) {
          //   // 判断列表后台反馈数据总量=目前的数据量则结束
          //   this.finished1 = true;
          // }
          // // 数据全部加载完成
          // if (this.list2.length >= this.totalCount2) {
          //   // 判断列表后台反馈数据总量=目前的数据量则结束
          //   this.finished2 = true;
          // }
          // // 数据全部加载完成
          // if (this.list3.length >= this.totalCount3) {
          //   // 判断列表后台反馈数据总量=目前的数据量则结束
          //   this.finished3 = true;
          // }
        // }, 1000);
      },
      // 请求获取街坊公告信息
      // 注册了，dataAreaCode传当前所在区划；没注册传dataAreaCode: ''。
      requestPostNotice1() {
        if (this.slow.isAuth) {
          // if (this.slow.isAuth && this.slow.userInfo.subscribe != 0) {
          this.post("Info_publish/loadInfo_public", {
              pageSize: 10,
              // pageIndex: this.pageIndex1,
              pageIndex: this.currentPage,
              dataAreaCode: sessionStorage.getItem("dataAreaCode"),
              startTime: "2018-10-06 00:00:00",
              endTime: "2020-11-06 00:00:00",
              type: 1
            })
            .then(res => {
              console.log("反馈", res);
              if (res.array.length) {
                // this.list1 = this.list1.concat(res.array);
                // this.pageIndex1 += 1;
                // this.totalCount1 = res.pageInfo.totalCount;
                this.allcount = Number(res.pageInfo.pageCount);
                this.list1 = res.array
              }
            })
            .catch(err => {
              console.log("异常", err);
            });
        } else {
          this.post("Info_publish/loadInfo_public", {
              pageSize: 10,
              // pageIndex: this.pageIndex1,
              pageIndex: this.currentPage,
              dataAreaCode: '',
              startTime: "2018-10-06 00:00:00",
              endTime: "2020-11-06 00:00:00",
              type: 1
            })
            .then(res => {
              console.log("反馈", res);
              if (res.array.length) {
                // this.list1 = this.list1.concat(res.array);
                // this.pageIndex1 += 1;
                // this.totalCount1 = res.pageInfo.totalCount;
                this.allcount = Number(res.pageInfo.pageCount);
                this.list1 = res.array
              }
            })
            .catch(err => {
              console.log("异常", err);
            });
        }
      },
      requestPostNotice2() {
        if(this.slow.isAuth){
          // if (this.slow.isAuth && this.slow.userInfo.subscribe != 0) {
          this.post("Info_publish/loadInfo_public", {
            pageSize: 10,
            // pageIndex: this.pageIndex2,
            pageIndex: this.currentPage,
            dataAreaCode: sessionStorage.getItem("dataAreaCode"),
            startTime: "2019-10-06 00:00:00",
            endTime: "2019-11-06 00:00:00",
            type: 2
          })
          .then(res => {
            console.log("反馈", res);
            if (res.array.length) {
              // this.list2 = res.array;
              // this.pageIndex2 += 1;
              // this.totalCount2 = res.pageInfo.totalCount;
              this.allcount = Number(res.pageInfo.pageCount);
              this.list2 = res.array
            }
          })
          .catch(err => {
            console.log("异常", err);
          });
        }else{
          this.post("Info_publish/loadInfo_public", {
            pageSize: 10,
            // pageIndex: this.pageIndex2,
            pageIndex: this.currentPage,
            dataAreaCode: '',
            startTime: "2019-10-06 00:00:00",
            endTime: "2019-11-06 00:00:00",
            type: 2
          })
          .then(res => {
            console.log("反馈", res);
            if (res.array.length) {
              // this.list2 = res.array;
              // this.pageIndex2 += 1;
              // this.totalCount2 = res.pageInfo.totalCount;
              this.allcount = Number(res.pageInfo.pageCount);
              this.list2 = res.array
            }
          })
          .catch(err => {
            console.log("异常", err);
          });
        }
      },
      requestPostNotice3() {
        if(this.slow.isAuth){
          // if (this.slow.isAuth && this.slow.userInfo.subscribe != 0) {
          this.post("Info_publish/loadInfo_public", {
            pageSize: 10,
            // pageIndex: this.pageIndex3,
            pageIndex: this.currentPage,
            dataAreaCode: sessionStorage.getItem("dataAreaCode"),
            startTime: "2019-10-06 00:00:00",
            endTime: "2019-11-06 00:00:00",
            type: 3
          })
          .then(res => {
            console.log("反馈", res);
            if (res.array.length) {
              // this.list3 = res.array;
              // this.pageIndex3 += 1;
              // this.totalCount3 = res.pageInfo.totalCount;
              this.allcount = Number(res.pageInfo.pageCount);
              this.list3 = res.array
            }
          })
          .catch(err => {
            console.log("异常", err);
          });
        }else{
          this.post("Info_publish/loadInfo_public", {
            pageSize: 10,
            // pageIndex: this.pageIndex3,
            pageIndex: this.currentPage,
            dataAreaCode: '',
            startTime: "2019-10-06 00:00:00",
            endTime: "2019-11-06 00:00:00",
            type: 3
          })
          .then(res => {
            console.log("反馈", res);
            if (res.array.length) {
              // this.list3 = res.array;
              // this.pageIndex3 += 1;
              // this.totalCount3 = res.pageInfo.totalCount;
              this.allcount = Number(res.pageInfo.pageCount);
              this.list3 = res.array
            }
          })
          .catch(err => {
            console.log("异常", err);
          });
        }
      }
    }
  };
</script>
<style lang="scss" scoped>
  @import "~@/smobile.scss";
  .NoticeList {
    overflow-y: unset !important;
    .header {
      padding: $sm-spaceing-block-sm 0 $sm-spaceing-block-sm 0;
      position: absolute;
      width: $sm-img-per-max;
      height: 21px;
      background: $sm-bg-color;
      z-index: 2;
      display: flex;
      flex-direction: row nowrap;
      justify-content: flex-start;
      .backIcon {
        position: absolute;
        white-space: nowrap;
        height: $sm-icon-px-md;
        z-index: 4;
        .iconImage {
          height: $sm-icon-px-md;
          width: $sm-icon-px-md;
          transform: rotateY(180deg);
        }
      }
      .theme {
        position: absolute;
        font-weight: bold;
        width: $sm-img-per-max;
        text-align: center;
        white-space: nowrap;
        z-index: 3;
      }
    }
    .outermostMargin {
      background: $sm-bg-color-grey;
      color: $sm-text-color;
      font-size: $sm-font-size-lg;
      overflow: auto;
      // height: 100vh; // margin: 41px 0 0 0;
      height: calc(100vh - 86px);
      .listBox {
        display: flex;
        flex-direction: column;
        background-color: $sm-bg-color;
        .msgBox {
          width: 90vw;
          display: flex;
          flex-direction: row;
          flex-wrap: nowrap;
          justify-content: space-between;
          .textBox {
            width: 58vw;
            .titles {
              display: flex;
              flex-direction: column;
              margin: $sm-spacing-col-xl 0 0 0;
              .mainTitle {
                font-size: $sm-font-size-title;
                font-weight: bold;
                color: $sm-color-title;
              }
              p{
                display: flex;
                justify-content: space-between;
                span:nth-child(2){
                  font-size: $sm-font-size-sm;
                  background: #e5b03e;
                  padding: 3px 6px;
                  border-radius: 12px;
                  color: #ffffff;
                }
                .time {
                  color: $sm-text-color-grey;
                  font-size: $sm-font-size-sm;
                }
              }
            }
            .summary {
              margin: $sm-spacing-col-lg 0 $sm-spacing-col-lg 0;
              text-overflow: -o-ellipsis-lastline;
              overflow: hidden;
              text-overflow: ellipsis;
              display: -webkit-box;
              -webkit-line-clamp: 2;
              line-clamp: 2;
              -webkit-box-orient: vertical;
              color: $sm-color-title;
            }
          }
          .imgBox {
            // height: $sm-img-size-max;
            width: 30vw;
            img {
              width: 100%;
            }
          }
        }
      }
    }
    .pages {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        z-index: 111;
        background: #ffffff;
      }
  }
</style>